home *** CD-ROM | disk | FTP | other *** search
/ Celestin Apprentice 4 / Apprentice-Release4.iso / Source Code / Libraries / Graphic Elements 3 / Misc / GUtilities.c < prev    next >
Text File  |  1995-08-28  |  3KB  |  134 lines

  1. /*
  2.     GUtilities.c
  3.     
  4.     General-purpose utility routines
  5.     
  6. */
  7.  
  8. #include "GUtilities.h"
  9. #include <stdio.h>
  10. #include <string.h>
  11.  
  12. //Globals
  13. Str255        gAppName;
  14. OSType        gSignature;
  15. short        gAppResRef;
  16. Boolean        gInBackground = false;
  17.  
  18. //Are we using the new headers?
  19. #if defined(__CONDITIONALMACROS__)
  20. #define NEWHEADERS 1
  21. #else
  22. #define NEWHEADERS 0
  23. #endif
  24.  
  25. #if FORPPC
  26. extern QDGlobals    qd;
  27. #endif
  28.  
  29. Handle    GetAppIndResource(ResType theType, short index, OSErr *err)
  30. {
  31. #pragma unused (err)
  32.  
  33.     short    savedResFile;
  34.     Handle    returnHandle;
  35.     
  36.     savedResFile = CurResFile ();
  37.     UseResFile (gAppResRef);
  38.     returnHandle = Get1IndResource(theType, index);
  39.     UseResFile (savedResFile);
  40.     return (returnHandle);
  41. }
  42.  
  43. void InitSystem( short mbCount )
  44. {
  45.     short counter;
  46.     Handle    apParam;
  47.     Handle    bndlResource;
  48.     OSErr    err;
  49.     
  50.     for (counter = 0; counter < mbCount; counter++)
  51.         MoreMasters();
  52.     InitGraf(&qd.thePort);
  53.     InitFonts();
  54.     InitWindows();
  55.     TEInit();
  56.     InitMenus();
  57.     InitDialogs(0L);
  58.     DrawMenuBar();
  59.     FlushEvents(everyEvent,0L);
  60.     InitCursor();
  61.     InitAllPacks();
  62. #if NEWHEADERS
  63.     BlockMove((Ptr) LMGetCurApName(), &gAppName, 255);
  64.     gAppResRef =  LMGetCurApRefNum();
  65.     apParam = LMGetAppParmHandle();
  66. #else
  67.     GetAppParms(gAppName, &gAppResRef, &apParam);
  68. #endif
  69.     bndlResource = GetAppIndResource('BNDL', 1, &err);
  70.     if (bndlResource)
  71.         gSignature = *(OSType *) (*bndlResource);
  72.  
  73. }
  74.  
  75. Boolean LoadMenus( short mBarNum )
  76. {
  77.     Handle    menuBar;
  78.     
  79.     menuBar = GetNewMBar(mBarNum);    
  80.     if (!menuBar)
  81.         return false;
  82.     SetMenuBar(menuBar);                    /* install menus */
  83.     DisposHandle(menuBar);
  84.     AddResMenu(GetMHandle(mApple), 'DRVR');    /* add DA names to Apple menu */
  85.     DrawMenuBar();
  86.     return true;
  87. }
  88.  
  89. void TellUser(Str255 what, short errNum)
  90. {
  91.     short        itemHit;
  92.     unsigned char    errNumStr[256];
  93.     
  94.     SetCursor(&qd.arrow);
  95.     if (errNum) 
  96.         sprintf((char *) &errNumStr, "Significant number: %d", errNum);
  97.     else
  98.         sprintf((char *) &errNumStr, "No error number to report", 0);
  99.     ParamText(what, (ConstStr255Param) c2pstr((char *) errNumStr),nil,nil);
  100.     itemHit = NoteAlert(rUserAlert, nil);
  101. }
  102.  
  103. char *C2PStrCpy(char *Cstr, Str255 Pstr)
  104. {
  105.     short i, len = strlen(Cstr);
  106.     
  107.     for(i=len; i>0; i--) {
  108.         Pstr[i] = Cstr[i-1];
  109.     }
  110.     Pstr[i] = len;
  111.     
  112.     return( (char *) Pstr );
  113. }
  114.  
  115. Boolean GetOpenFSSpec(SFTypeList *types, short nTypes, FSSpec *fileSpec)
  116. {
  117.     StandardFileReply    openReply;
  118.     
  119.     StandardGetFile(nil, nTypes, *types, &openReply);
  120.     *fileSpec = openReply.sfFile;
  121.     return(openReply.sfGood);
  122. }
  123.  
  124. Boolean GetSaveFSSpec(SFTypeList *types, FSSpec *fileSpec)
  125. {
  126.     StandardFileReply    saveReply;
  127.     
  128.     StandardPutFile((ConstStr255Param) "\pSave as:",(ConstStr255Param) "", &saveReply);
  129.     
  130.     *fileSpec = saveReply.sfFile;
  131.     return (saveReply.sfGood);
  132. }
  133.  
  134.